let huaBu = document.querySelector('#hua-bu');
huaBu.width = document.body.scrollWidth;
huaBu.height = document.body.scrollHeight;

// huaBu.height = parseInt(window.getComputedStyle(huaBu).height);

ctx = huaBu.getContext('2d');
ctx.fillStyle = 'rgba(11, 13, 26, 1)';
ctx.fillRect(0, 0, huaBu.width, huaBu.height);
//画星
function huaXing(ctx, suiJi) {
	ctx.fillRect(0, 0, suiJi *1.5, suiJi * 1.5)
}
let xingShuZu = [];
class Xing {
		constructor() {
			this.x = Math.random() * huaBu.width;
			this.y = Math.random() * huaBu.height;
			this.r = Math.random();
			this.sGuDing = Math.random();
			this.s = this.sGuDing;
		}
		shanShuo() {
			this.s += 0.04;
			if (this.s >= 1) {
				this.s = this.sGuDing;
			}
		}
	}
for (var i = 0; i < 5000; i ++) {
	xingShuZu.push(new Xing())
}

function qunXing() {
	xingShuZu.forEach( p => {
			p.shanShuo();
		})
	ctx.fillRect(0, 0, huaBu.width, huaBu.height);
	xingShuZu.forEach( p => {
		ctx.save();
		ctx.fillStyle = `rgba(170, 213, 255, ${Number(p.s)})`;
		ctx.translate(p.x, p.y);
		huaXing(ctx, p.r);
		ctx.restore();
	})
}

function hua() {
	qunXing();
	window.requestAnimationFrame(hua);
}
hua()
